package com.guodexiain.nyiotclient.config;

import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.region.Region;
import com.huaweicloud.sdk.iotda.v5.IoTDAClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 类说明: <br>
 * <a href="http://www.xuejiaao.com">北京学佳澳教育科技有限公司</a>
 *
 * @author 作者:南阳德刚<br>
 * 2024-10-16 9:23
 */
@Configuration

public class IotConfig {
    @Autowired
    private IotConfigProperties iotConfig;
    @Bean
    public IoTDAClient ioTDAClient(){
        // 创建认证
        ICredential auth = new BasicCredentials().withAk(iotConfig.getAk()).withSk(iotConfig.getSk())
// 标准版/企业版需要使用衍生算法，基础版请删除配置"withDerivedPredicate"
                .withDerivedPredicate(BasicCredentials.DEFAULT_DERIVED_PREDICATE)
                .withProjectId(iotConfig.getProjectid());
// 创建IoTDAClient实例并初始化
        IoTDAClient client= IoTDAClient.newBuilder().withCredential(auth)
                .withRegion(new Region(iotConfig.getRegin_id(), iotConfig.getEndpoint()))
                .build();
        return  client;
    }
}
